#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>
#include <QDialog>
#include "showimages.h"
#include "calculators.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    setWindowIcon(QIcon("icon.ico"));
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::radioChanged()
{
    if(sender() == ui->BHT_radioButton) {
        ui->BHT_radioButton->setChecked(true);
        ui->Blocking_radioButton->setChecked(false);
        ui->Lines_radioButton->setChecked(false);
        ui->BHT_lineEdit->setEnabled(false);
        ui->Blocking_lineEdit->setEnabled(true);
        ui->Lines_lineEdit->setEnabled(true);
        ui->BHT_lineEdit->setText("");
//        ui->Blocking_lineEdit->clear();
//        ui->Lines_lineEdit->clear();
    }
    else if(sender() == ui->Blocking_radioButton) {
        ui->BHT_radioButton->setChecked(false);
        ui->Blocking_radioButton->setChecked(true);
        ui->Lines_radioButton->setChecked(false);
        ui->BHT_lineEdit->setEnabled(true);
        ui->Blocking_lineEdit->setEnabled(false);
        ui->Lines_lineEdit->setEnabled(true);
        ui->Blocking_lineEdit->setText("");
//        ui->BHT_lineEdit->clear();
//        ui->Lines_lineEdit->clear();
    } else {
        ui->BHT_radioButton->setChecked(false);
        ui->Blocking_radioButton->setChecked(false);
        ui->Lines_radioButton->setChecked(true);
        ui->BHT_lineEdit->setEnabled(true);
        ui->Blocking_lineEdit->setEnabled(true);
        ui->Lines_lineEdit->setEnabled(false);
        ui->Lines_lineEdit->setText("");
//        ui->BHT_lineEdit->clear();
//        ui->Blocking_lineEdit->clear();
    }
}


void MainWindow::on_Calculate_pushButton_clicked()
{
    QString str;
    double a = ui->BHT_lineEdit->text().toDouble(),
        b = ui->Blocking_lineEdit->text().toDouble();
    int s = ui->Lines_lineEdit->text().toInt();
    if(ui->BHT_radioButton->isChecked()){
        if(!(s&&b) || s<1 || s>180 || b<0.001 || b>0.999){
            QMessageBox::warning(this, "温馨提示", tr("请同时输入符合条件的s和b   1<=s<=180   0.001<=b<=0.999"));
        }else {
            a = calculate_a(s, b);
            str = QString::number(a);
            ui->BHT_lineEdit->setText(str);
        }

    } else if(ui->Blocking_radioButton->isChecked()){
        if(!(a&&s) || s<1 || s>180 || a<0.1 || a>180){
            QMessageBox::warning(this, "温馨提示", tr("请同时输入符合条件的a和s   0.1<=a<=180   1<=s<=180,"));
        }else {
            b = calculate_b(a, s);
            str = QString::number(b);
            ui->Blocking_lineEdit->setText(str);
        }

    } else{
        if(!(b&&a) || b<0.001 || b>0.999 || a<0.1 || a>180){
            QMessageBox::warning(this, "温馨提示", tr("请同时输入符合条件的a和b   0.1<=a<=180   0.001<=b<=0.999"));
        } else {
            s = calculate_s(b, a);
            str = QString::number(s);
            ui->Lines_lineEdit->setText(str);
        }

    }
}

void MainWindow::on_showImage_Button_clicked()
{
    ShowImages simg;
    simg.exec();
}

